package ru.averta.notes.tests;

import ru.averta.notes.domain.Site;
import ru.averta.notes.domain.User;
import ru.averta.notes.other.UtilsCommon;
import ru.averta.notes.service.UrlService;

public class SiteSubjectFactory {
    private static UrlService urlService;

    private static UrlService getUrlService() {
        if (urlService == null) urlService = (UrlService) UtilsCommon.getBean(UrlService.class);
        return urlService;
    }

    public static Site createValidSiteSubject() {
        return createValidSiteSubject("url");
    }

    public static Site createValidSiteSubject(String url) {
        Site site = new Site();
        site.setTitle(url);
        site.setUrl(getUrlService().findOrCreateUrl(url));
        return site;
    }

    public static Site createValidSiteSubject(String url, User user) {
        Site site = createValidSiteSubject(url);
        site.setUser(user);
        return site;
    }

}
